package com.ruoyi.welder.controller;

import java.util.List;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.ui.ModelMap;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.welder.domain.WelderAnalysis;
import com.ruoyi.welder.service.IWelderAnalysisService;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 焊工数据统计分析Controller
 * 
 * @author ruoyi
 * @date 2023-01-12
 */
@Controller
@RequestMapping("/welder/analysis")
public class WelderAnalysisController extends BaseController
{
    private String prefix = "welder/analysis";

    @Autowired
    private IWelderAnalysisService welderAnalysisService;

    @RequiresPermissions("welder:analysis:view")
    @GetMapping()
    public String analysis()
    {
        return prefix + "/analysis";
    }

    /**
     * 查询焊工数据统计分析列表
     */
    @RequiresPermissions("welder:analysis:list")
    @PostMapping("/list")
    @ResponseBody
    public TableDataInfo list(WelderAnalysis welderAnalysis)
    {
        startPage();
        List<WelderAnalysis> list = welderAnalysisService.selectWelderAnalysisList(welderAnalysis);
        return getDataTable(list);
    }

    /**
     * 导出焊工数据统计分析列表
     */
    @RequiresPermissions("welder:analysis:export")
    @Log(title = "焊工数据统计分析", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    @ResponseBody
    public AjaxResult export(WelderAnalysis welderAnalysis)
    {
        List<WelderAnalysis> list = welderAnalysisService.selectWelderAnalysisList(welderAnalysis);
        ExcelUtil<WelderAnalysis> util = new ExcelUtil<WelderAnalysis>(WelderAnalysis.class);
        return util.exportExcel(list, "焊工数据统计分析数据");
    }

    /**
     * 新增焊工数据统计分析
     */
    @GetMapping("/add")
    public String add()
    {
        return prefix + "/add";
    }

    /**
     * 新增保存焊工数据统计分析
     */
    @RequiresPermissions("welder:analysis:add")
    @Log(title = "焊工数据统计分析", businessType = BusinessType.INSERT)
    @PostMapping("/add")
    @ResponseBody
    public AjaxResult addSave(WelderAnalysis welderAnalysis)
    {
        return toAjax(welderAnalysisService.insertWelderAnalysis(welderAnalysis));
    }

    /**
     * 修改焊工数据统计分析
     */
    @RequiresPermissions("welder:analysis:edit")
    @GetMapping("/edit/{welderId}")
    public String edit(@PathVariable("welderId") String welderId, ModelMap mmap)
    {
        WelderAnalysis welderAnalysis = welderAnalysisService.selectWelderAnalysisByWelderId(welderId);
        mmap.put("welderAnalysis", welderAnalysis);
        return prefix + "/edit";
    }

    /**
     * 修改保存焊工数据统计分析
     */
    @RequiresPermissions("welder:analysis:edit")
    @Log(title = "焊工数据统计分析", businessType = BusinessType.UPDATE)
    @PostMapping("/edit")
    @ResponseBody
    public AjaxResult editSave(WelderAnalysis welderAnalysis)
    {
        return toAjax(welderAnalysisService.updateWelderAnalysis(welderAnalysis));
    }

    /**
     * 删除焊工数据统计分析
     */
    @RequiresPermissions("welder:analysis:remove")
    @Log(title = "焊工数据统计分析", businessType = BusinessType.DELETE)
    @PostMapping( "/remove")
    @ResponseBody
    public AjaxResult remove(String ids)
    {
        return toAjax(welderAnalysisService.deleteWelderAnalysisByWelderIds(ids));
    }
}
